VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsRegistry"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit

Public Property Let PhoneEntry(ByVal vData As String)
   'sets the system in the registry
    SaveSettingC "Software\Mindkey\SendKey\Destinations\" & strDestination, "PhoneEntry", vData, REG_SZ
End Property

Public Property Get PhoneEntry(strDestination As String) As String
'used when retrieving value of a property, on the right side of an assignment.
    PhoneEntry = GetSettingC("Software\Mindkey\SendKey\Destinations\" & strDestination, "PhoneEntry")
End Property

Public Property Get ShareName(strDestination As String) As String
'used when retrieving value of a property, on the right side of an assignment.
    ShareName = GetSettingC("Software\Mindkey\SendKey\Destinations\" & strDestination, "ShareName")
End Property

Public Property Let ShareName(ByVal vData As String)
   'sets the system in the registry
    SaveSettingC "Software\Mindkey\SendKey\Destinations\" & strDestination, "ShareName", vData, REG_SZ
End Property

Public Property Let UserName(ByVal vData As String)
   'sets the system in the registry
    SaveSettingC "Software\Mindkey\SendKey\Destinations\" & strDestination, "UserName", vData, REG_SZ
End Property

Public Property Get UserName(strDestination As String) As String
'used when retrieving value of a property, on the right side of an assignment.
    UserName = GetSettingC("Software\Mindkey\SendKey\Destinations\" & strDestination, "UserName")
End Property

Public Property Let Password(ByVal vData As String)
   'sets the system in the registry
    SaveSettingC "Software\Mindkey\SendKey\Source" & strDestination, "Password", vData, REG_SZ
End Property

Public Property Get Password(strDestination As String) As String
'used when retrieving value of a property, on the right side of an assignment.
    Password = GetSettingC("Software\Mindkey\SendKey\Destinations\" & strDestination, "Password")
End Property

Public Property Let DeleteFiles(ByVal vData As String)
   'sets the system in the registry
    SaveSettingC "Software\Mindkey\SendKey\Source", "DeleteFiles", vData, REG_SZ
End Property

Public Property Get DeleteFiles() As String
'used when retrieving value of a property, on the right side of an assignment.
    DeleteFiles = GetSettingC("Software\Mindkey\SendKey\Source", "DeleteFiles")
End Property

Public Property Get MoveFolder() As String
'used when retrieving value of a property, on the right side of an assignment.
    MoveFolder = GetSettingC("Software\Mindkey\SendKey\Source", "MoveFolder")
End Property

Public Property Let MoveFolder(ByVal vData As String)
   'sets the system in the registry
    SaveSettingC "Software\Mindkey\SendKey\Source", "MoveFolder", vData, REG_SZ
End Property

Public Property Get BranchCode() As String
'used when retrieving value of a property, on the right side of an assignment.
    BranchCode = GetSettingC("Software\Mindkey\SendKey\Source", "BranchCode")
End Property

Public Property Let BranchCode(ByVal vData As String)
   'sets the system in the registry
    SaveSettingC "Software\Mindkey\SendKey\Source", "BranchCode", vData, REG_SZ
End Property

Public Property Get LogFolder() As String
'used when retrieving value of a property, on the right side of an assignment.
    LogFolder = GetSettingC("Software\Mindkey\SendKey\Source", "LogFolder")
End Property

Public Property Let LogFolder(ByVal vData As String)
   'sets the system in the registry
    SaveSettingC "Software\Mindkey\SendKey\Source", "LogFolder", vData, REG_SZ
End Property

Private Sub SaveSettingC(strKeyName As String, strValueName As String, varValueSetting As Variant, lngValueType As Long)
'Purpose
'*******
'Set the value of a Registry key if it exists.
'if the registry key doesn't exist it will be created

On Error GoTo SaveSettingsCFix

'Variables
'*********
    Dim hKey As Long            'Handle to the key
    Dim lngRetVal As Long       'Result of API functions
    Dim SA As SECURITY_ATTRIBUTES
    Dim create As Long

'Code
'****
    'Open or Ceate the registry key
    lngRetVal = RegCreateKeyEx(HKEY_LOCAL_MACHINE, strKeyName, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, SA, hKey, create)
    If lngRetVal <> ERROR_SUCCESS Then
        MsgBox "An error occured while trying to set the registry key", vbExclamation
        Exit Sub
    End If
    
    'Set or create a registry value
    lngRetVal = RegSetValueEx(hKey, strValueName, 0, lngValueType, varValueSetting, CLng(Len(varValueSetting) + 1))
        
    RegCloseKey (hKey)
    
    Exit Sub
    
SaveSettingsCFix:
    Call LogErrors(Format(Date, "ddmm") & "Error.Log", "Error setting registry")
    Resume Next
End Sub

Private Function GetSettingRep(strKeyName As String, strValueName As String) As Integer

'Purpose
'*******
'Gets the value a certain registry key

On Error GoTo GetSettingsRepFix

'Variables
'*********
    Dim lngRetVal As Long           'Result of the API functions
    Dim hKey As Long                'Handle of the opened key
    Dim szBuffer As String          'Setting of the queried value
    Dim lngBuffSize As Long
    
'Code
'****
    'Create the buffer
    szBuffer = Space(255)
    lngBuffSize = 255
    
    'Open the specified registry key
    lngRetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strKeyName, 0, KEY_ALL_ACCESS, hKey)
    If lngRetVal <> ERROR_SUCCESS Then
        GetSettingRep = -1
        Exit Function
    End If
    
    'Read the opened registry key
    lngRetVal = RegQueryValueEx(hKey, strValueName, 0, REG_DWORD, szBuffer, lngBuffSize)
    
    'Converts the Hex number to a decimal number
    '-------------------------------------------
    Dim x As String
    Dim y As String
    Dim z As Long
    x = Num2Bin(Asc(Mid(szBuffer, 1, 1)))
    y = Num2Bin(Asc(Mid(szBuffer, 2, 1)))
    z = Bin2Num(Right(y, 8) & Right(x, 8))
    '-------------------------------------------
   
    GetSettingRep = CInt(z)

    'Close the registry key
    RegCloseKey (hKey)

    Exit Function
    
GetSettingsRepFix:
    Call LogErrors(Format(Date, "ddmm") & "Error.Log", "Error setting registry")
    Resume Next
End Function
Private Function GetSettingC(strKeyName As String, strValueName As String) As String
'Purpose
'*******
'Gets the value a certain registry key

On Error GoTo GetSettingsCFix

'Variables
'*********
    Dim lngRetVal As Long           'Result of the API functions
    Dim hKey As Long                'Handle of the opened key
    Dim szBuffer As String          'Setting of the queried value
    Dim lngBuffSize As Long
    
'Code
'****
    'Create the buffer
    szBuffer = Space(255)
    lngBuffSize = 255
    
    'Open the specified registry key
    lngRetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strKeyName, 0, KEY_ALL_ACCESS, hKey)
    If lngRetVal <> ERROR_SUCCESS Then
        'MsgBox "Registry key or Value Name doesn't exist", vbExclamation
        Exit Function
    End If
    
    'Read the opened registry key
    lngRetVal = RegQueryValueEx(hKey, strValueName, 0, 0, szBuffer, lngBuffSize)
    
    GetSettingC = Trim(Left(szBuffer, lngBuffSize - 1))
    
    'Close the registry key
    RegCloseKey (hKey)

    Exit Function
    
GetSettingsCFix:
    Call LogErrors(Format(Date, "ddmm") & "Error.Log", "Error setting registry")
    Resume Next
End Function

